package ModelLayer;
import java.util.ArrayList;

public class SaleContainer
{
    public ArrayList<Sale> saleContainer;
    public static SaleContainer instance;
   
    public SaleContainer()
    {
       saleContainer = new ArrayList<Sale>();
    }
    public static SaleContainer getInstance()
    {
        if(instance == null)
        {
            instance = new SaleContainer();
        }
        return instance;
    }
    
     public void addSale(Sale sale)
    {
       saleContainer.add(sale);
    }
    public void createSale(Customer customer, Specimen specimen, Staff staff, int saleID)
    {
        Sale sale = new Sale(customer, specimen, staff, saleID);
        saleContainer.add(sale);
    }
    
    public Sale findSale(String personPhone)
    {
        Sale sale = null;
        int index = 0;
        boolean found = false;
        while(index < saleContainer.size() && !found)
        {
            sale = saleContainer.get(index);
            Customer customer = sale.getCustomer();
            if(customer.getPhoneNo().equals(personPhone))
            {
                found = true;
            }
            else
            {
                index++;
            }
        }
        return sale;
    }
    public ArrayList<Sale> findAllSales(String phone)
    {
        ArrayList<Sale> foundSale = new ArrayList<Sale>();
        for (Sale sale : saleContainer)
        {
            Customer customer = sale.getCustomer();
            if(customer.getPhoneNo().equals(phone))
            {
                foundSale.add(sale);
            }
        } 
        return foundSale;
    }
    public void deleteSale(int id)
    {
        int index = 0;
        boolean found = false;
        while(index < saleContainer.size() && !found)
        {
            if(saleContainer.get(index).getSaleID() == id)
            {
                saleContainer.remove(index);
                found = true;
            }
            else
            {
                index++;
            }
        }
    }
    public ArrayList<Sale> listAllSales()
    {
        return saleContainer;
    }
    

    
  
}
